<?php

namespace App\Console\Commands\Kms;

use App\Models\Kms\KmsIosCode;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class SyncIosCode extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'kms:syncIosCode';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '从数据库同步ios下载code';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        KmsIosCode::query()
            ->where('status', KmsIosCode::STATUS_NOT_USE)// 未使用
            ->chunkById(
                100, function ($item) {
                foreach ($item as $v) {

                    dump($v->code);
                    //添加到redis中
                    Redis::sAdd(KmsIosCode::KMS_IOS_DOWNLOAD_CODE, (string)$v->code);
                }
            }
            );

        $count = Redis::sCard(KmsIosCode::KMS_IOS_DOWNLOAD_CODE);
        dump('夸父运营IOS下载code数量：' . $count);
    }
}

